package me.minecraft.plugin.itemsave.command;

import me.minecraft.plugin.itemsave.manager.ItemManager;
import org.bukkit.command.CommandSender;

import java.util.List;

/**
 * @author langle__
 * @version 1.0
 */
public class DeleteCommand extends SubCommand {

    @Override
    public void onCommand(CommandSender sender, String[] args) {
        if (args.length < 1) {
            sender.sendMessage("[§6ItemSave§f] §c缺少名称");
            return;
        }
        String name = args[0];
        boolean deleted = ItemManager.INSTANCE.deleteItem(name);
        if (deleted) {
            sender.sendMessage("[§6ItemSave§f] 成功删除 " + name + " 物品");
        } else {
            sender.sendMessage("[§6ItemSave§f] §c物品 " + name + " 不存在");
        }
    }

    @Override
    public List<String> onTabComplete(CommandSender sender, String[] args) {
        if (args.length == 1) {
            return ItemManager.INSTANCE.keySet().stream().toList();
        }
        return List.of();
    }

}
